import java.util.InputMismatchException;
import java.util.Scanner;

class Person implements Cloneable{
    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}

public class demo1 {

    public static void test1() {
        int[] array = {1,2,3,4};
        System.out.println(array[10]);
    }

    public static void main(String[] args) {
        try {
            test1();
            System.out.println("结束try的代码.....");
        }catch (ArrayIndexOutOfBoundsException e) {

        }
        System.out.println("fsfadsafsa");
    }

    public static void main7(String[] args) {
        System.out.println(testFinally());
    }

    private static int testFinally() {
        try {
            return 10;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally中的代码");
            return 20;
        }
    }

    public static int getData(){
        Scanner scanner = null;
        try {
            scanner = new Scanner(System.in);
            int data = scanner.nextInt();
            return data;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally中代码");
        }
        System.out.println("try-catch-finally之后代码");
        if (scanner != null){
            scanner.close();
        }
        return 0;
    }

    public static int getData1(){
        try (Scanner scanner = new Scanner(System.in)){
            int data = scanner.nextInt();
            return data;
        }catch (InputMismatchException e){
            e.printStackTrace();
        }finally {
            System.out.println("finally中代码");
        }
        System.out.println("try-catch-finally之后代码");
        return 0;
    }

    public static void main6(String[] args) {
        //finally 一般用于资源的释放
        int data = getData();
        System.out.println(data);
    }

    public static void main5(String[] args) {
        int[] array = {1,2,3};
        try{
            System.out.println(array[10]);
            array = null;
            System.out.println(array.length);
        }catch (ArrayIndexOutOfBoundsException e){
            System.out.println("处理ArrayIndexOutOfBoundsException异常....");
            e.printStackTrace();
        }catch (NullPointerException e){
            System.out.println("处理NullPointerException异常....");
            e.printStackTrace();
        }
        System.out.println("after");
    }

    public static void function(int a) throws CloneNotSupportedException {
        if (a == 10){
            throw new CloneNotSupportedException();
        }
    }

    public static void main4(String[] args) {
        try {
            function(10);
            System.out.println("哈哈.....");
        } catch (CloneNotSupportedException e) {
            System.out.println("捕获了异常，处理异常....");
        }
        System.out.println("程序正常继续执行...");
    }

    public static void testException(int a){
        if(a == 0){
            throw new ArithmeticException("a == 0");
        }
    }

    public static void main3(String[] args) {
        testException(0);
    }

    public static void main2(String[] args) throws CloneNotSupportedException {
        Person person = new Person();
        Person person1 = (Person) person.clone();
    }

    public static void main1(String[] args) {
//        //System.out.println(10/0);
//        int[] array = {1,2,3,4,5};
//        System.out.println(array[10]);
        int[] array = null;
        System.out.println(array.length);
    }
}
